﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Generic.Contract;
using Generic.Data.Manager;

namespace Generic.Business.Manager
{
    public abstract class BMGeneric<BE,FE,DM> : BusinessManager<BE, FE, DM>, IBMGeneric<BE, FE>
        where BE : BusinessEntity, new()
        where FE : FilterEntity, new()
        where DM : IDataManager<BE, FE>, new()
    {
        public BMGeneric()
            : base()
        {
        }

        #region IBMGeneric<BE,FE> Members

        public BE Copiar(BE entity)
        {
            throw new NotImplementedException();
        }

        public List<BE> ObterTodos(FE filter)
        {
            return this.DataManager.ObterTodos(filter);
        }

        public BE ObterEntidade(int codigo)
        {
            return this.DataManager.ObterEntidade(codigo);
        }

        public void Excluir(BE entity)
        {
            this.DataManager.Excluir(entity);
        }

        public void Excluir(List<BE> listEntity)
        {
            foreach (BE be in listEntity)
            {
                this.DataManager.Excluir(be);
            }
        }

        public virtual BE Salvar(BE entity)
        {
            return this.DataManager.Salvar(entity);
        }

        public List<BE> Salvar(List<BE> listEntity)
        {
            List<BE> retorno = new List<BE>();

            foreach (BE be in listEntity)
            {
                retorno.Add(this.DataManager.Salvar(be));
            }

            return retorno;
        }

        #endregion
    }
}
